package com.hengxinguotong.zhihuichengjian.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.hengxinguotong.zhihuichengjian.R;
import com.hengxinguotong.zhihuichengjian.bean.Team;
import com.hengxinguotong.zhihuichengjian.bean.WorkType;
import com.hengxinguotong.zhihuichengjian.treeview.RecyclerAdapter;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2018/2/8.
 *
 * 工种列表适配器
 */

public class TeamAdapter extends RecyclerAdapter<Team, TeamAdapter.TeamViewHolder> {

    public TeamAdapter(Context context, List<Team> dataList) {
        super(context, dataList);
    }

    @Override
    public TeamViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(context, R.layout.item_worktype, null);
        return new TeamViewHolder(view);
    }

    @Override
    public void onBindViewHolder(TeamViewHolder holder, int position) {
        holder.bindData(position);
    }

    public class TeamViewHolder extends RecyclerAdapter.BaseViewHolder
    {
        @BindView(R.id.name_tv)
        TextView nameTv;
        @BindView(R.id.flag_img)
        ImageView flagImg;

        public TeamViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }

        @Override
        public void bindData(final int position) {
            final Team team = dataList.get(position);
            nameTv.setText(team.getName());
            if(team.isSelected()){
                flagImg.setVisibility(View.VISIBLE);
            }else{
                flagImg.setVisibility(View.GONE);
            }
            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    onItemClickListener.onItemClick(itemView, team, position);
                }
            });
        }
    }

}
